using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Week1.world
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Draw2DBase : Microsoft.Xna.Framework.DrawableGameComponent
    {

        SpriteBatch oBatch;
        
        public struct Sprites
        {
            public Texture2D oSprite;
            public Rectangle oPosition;
        }

        protected Sprites[] oSprites;
        int iInstances;
        string sTextureName;

        public Draw2DBase(Game game, int instances, String textureName)
            : base(game)
        {
            iInstances = instances;
            sTextureName = textureName;
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            oSprites = new Sprites[iInstances];

            for (int iDx = 0; iDx < iInstances; iDx++)
            {
                oSprites[iDx] = new Sprites();
                oSprites[iDx].oPosition = new Rectangle(0,0,10,10);
            }

            base.Initialize();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="index"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public void setSpriteLocation(int index, int x, int y, int width, int height)
        {
            oSprites[index].oPosition.X = x;
            oSprites[index].oPosition.Y = y;
            oSprites[index].oPosition.Width = width;
            oSprites[index].oPosition.Height = height;
        }

        public void LoadTheContent()
        {
            LoadContent();
        }
        /// <summary>
        /// 
        /// </summary>
        protected override void LoadContent()
        {
            oSprites[0].oSprite = this.Game.Content.Load<Texture2D>(sTextureName);
            oBatch = new SpriteBatch(this.Game.GraphicsDevice);
            base.LoadContent();
        }        

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            oBatch.Begin();
            oBatch.Draw(oSprites[0].oSprite, oSprites[0].oPosition, Color.White);
            oBatch.End();

            base.Draw(gameTime);
        }
    }
}
